package com.production.CoursePlatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.production.CoursePlatform.entity.Studying;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface StudyingMapper extends BaseMapper<Studying> {

    @Select("SELECT COUNT(*) from studying WHERE ct_ID=#{ctID}")
    int getStudentNumberOfCtID (@Param("ctID") int ctID);

    // 查找特定 s_id 的所有记录
    @Select("SELECT * FROM studying WHERE s_id = #{sID}")
    List<Studying> findBySID(@Param("sID") String sID);

    // 插入新的 Studying 记录，不设置 cts_id
    @Insert("INSERT INTO studying (ct_id, s_id) VALUES (#{ct_id}, #{s_id})")
    int insertWithoutCTSID(Studying studying);

    // 更新 Studying 记录
    @Update("UPDATE studying SET ct_id = #{ct_id}, s_id = #{s_id} WHERE cts_id = #{cts_id}")
    int updateStudying(Studying studying);

    // 删除 Studying 记录
    @Delete("DELETE FROM studying WHERE cts_id = #{cts_id}")
    int deleteByCTS_ID(@Param("cts_id") int cts_id);
}

